package com.freeman.cement.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.freeman.cement.entity.*;
import com.freeman.cement.exception.AppException;
import com.freeman.cement.exception.AppExceptionCodeMsg;
import com.freeman.cement.mapper.CameraDao;
import com.freeman.cement.mapper.CameraGroupDao;
import com.freeman.cement.mapper.CameraSquareDao;
import com.freeman.cement.mapper.EzvizDao;
import com.freeman.cement.mapper.DeptDao;
import com.freeman.cement.myenum.Enabled;
import com.freeman.cement.service.CameraService;
import com.freeman.cement.util.ConfigUtil;
import com.freeman.cement.util.HttpUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class CameraServiceImpl implements CameraService {

    private static Logger logger = LoggerFactory.getLogger(CameraServiceImpl.class);
    private static String appKey = "";
    private static String appSecret = "";
    private static String url = "";

    static {
        try {
            appKey = ConfigUtil.readKey("ysAppKey");
            appSecret = ConfigUtil.readKey("ysAppSecret");
            url = ConfigUtil.readKey("ysUrl");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 萤石播放的accessToken
     */
    private static String accessToken = "";
    /**
     * 萤石播放的accessToken的过期时间
     */
    private static Long expireTime = null;

    //引用类型的自动注入@Autowired,@Resource
    @Resource
    private CameraDao cameraDao;

    @Resource
    private CameraSquareDao cameraSquareDao;

    @Resource
    private EzvizDao ezvizDao;

    @Resource
    private CameraGroupDao cameraGroupDao;

    @Resource
    private DeptDao deptDao;

    @Override
    public ResponseResult selectCameraByRegion(String regionIndexCode, Integer isEnabled, int pageNo, int pageSize) {
        if(StringUtils.isNotBlank(regionIndexCode)) {
            PageHelper.startPage(pageNo, pageSize, true);
            List<Camera> list = cameraDao.findCamera(regionIndexCode, isEnabled);
            PageInfo<Camera> pageInfo = new PageInfo<Camera>(list);
            return ResponseResult.success(pageInfo);
        } else {
            throw new AppException(AppExceptionCodeMsg.PARAM_IS_NULL);
        }
    }

    @Override
    public ResponseResult selectCameraByIndexCode(String cameraIndexCode) {
        if(StringUtils.isNotBlank(cameraIndexCode)){
            List<Camera> cameras = cameraDao.selectCameraByIndexCode(cameraIndexCode);
            //选出摄像头在平台的状态是启用的，摄像头id最大的，也就是最新添加的摄像头
            //Camera camera = cameras.stream().filter(s -> s.getIsEnabled() == Enabled.TRUE.getIndex()).max(Comparator.comparing(x ->x.getId())).get();
            Camera camera = cameras.stream().filter(s -> s.getIsEnabled() == Enabled.TRUE.getIndex()).findFirst().get();

            if(cameras != null){
                return ResponseResult.success(camera);
            } else {
                throw new AppException(AppExceptionCodeMsg.ID_NOT_EXISTS);
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.PARAM_IS_NULL);
        }
    }

    @Override
    public ResponseResult selectCameraById(int id) {
        if(id > 0){
            Camera camera = cameraDao.selectCameraByIdToMap(id);
            if(camera != null){
                return ResponseResult.success(camera);
            } else {
                throw new AppException(AppExceptionCodeMsg.ID_NOT_EXISTS);
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.ID_IS_NULL);
        }
    }

    /**
     * 获取摄像头详情，供移动端播放视频使用，包括摄像头四个播放地址和AccessToken
     * @param cameraIndexCode
     * @return
     */
    @Override
    public ResponseResult getCameraByIndexCode(String cameraIndexCode) {
        if(StringUtils.isNotBlank(cameraIndexCode)){
            List<Camera> cameras = cameraDao.selectCameraByIndexCode(cameraIndexCode);
            //选出摄像头在平台的状态是启用的，摄像头id最大的，也就是最新添加的摄像头
            //Camera camera = cameras.stream().filter(s -> s.getIsEnabled() == Enabled.TRUE.getIndex()).max(Comparator.comparing(x ->x.getId())).get();
            Camera camera = cameras.stream().filter(s -> s.getIsEnabled() == Enabled.TRUE.getIndex()).findFirst().get();

            if(camera != null){
                /**
                 * 访问萤石平台接口，获取AccessToken的原理
                 * 1、若现在没有AccessToken为空就直接获取，并记录缓存
                 * 2、若不为空就判断，过期时间是否临近，如果不临近就直接提供AccessToken，accessToken有效期7天
                 * 3、若临近过期，就访问萤石平台获取AccessToken，更新缓存，并对外提供
                 */
                if(StringUtils.isNotBlank(accessToken) && expireTime != null){
                    long now = new Date().getTime();
                    if(now >= expireTime){
                        refreshAccessToken();
                    }
                } else {
                    refreshAccessToken();
                }
                Map<String, Object> map = new HashMap<>();
                map.put("camera", camera);
                map.put("accessToken", accessToken);
                map.put("expireTime", expireTime);
                return ResponseResult.success(map);
            } else {
                throw new AppException(AppExceptionCodeMsg.ID_NOT_EXISTS);
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.PARAM_IS_NULL);
        }
    }

    private void refreshAccessToken()
    {
        Map<String, String> paras = new HashMap<>();
        paras.put("appKey", appKey);
        paras.put("appSecret", appSecret);
        try
        {
            String resp = HttpUtils.post(url, paras);
            JSONObject jo = JSON.parseObject(resp);
            if(jo.containsKey("code") && jo.get("code").toString().equals("200"))
            {
                if(jo.containsKey("data")){
                    JSONObject jd = jo.getJSONObject("data");
                    if(jd.containsKey("accessToken")){
                        accessToken = jd.getString("accessToken");
                    }
                    if(jd.containsKey("expireTime")){
                        Long exp = jd.getLong("expireTime");
                        if(exp > 0){
                            expireTime = exp;
                            System.out.println("获取到新的AccessToken，过期日期：" + new Date(exp).toString());
                        }
                    }
                }
            }
        } catch (Exception e){
            e.printStackTrace();
            logger.error("refreshAccessToken--->" + "发生错误:" + e.getMessage());
        }
    }

    @Override
    public ResponseResult selectCamera(Camera camera, int pageNo, int pageSize) {
        // 获取当前用户角色和用户ID
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String userRole = (String) request.getAttribute("userRole");
        
        // 非管理员用户只能查看其所在值班室的摄像头
        if (!"管理员".equals(userRole)) {
            Integer userId = (Integer) request.getAttribute("userId");
            Dept userDept = deptDao.selectDutyRoomByid(userId);
            if (userDept == null) {
                // 如果用户没有关联值班室，返回空列表
                return ResponseResult.success(new PageInfo<>(new ArrayList<>()));
            }
            
            // 强制使用用户所在值班室ID
            if (camera == null) {
                camera = new Camera();
            }
            camera.setDeptDutyId(userDept.getId());
        } else {
            // 管理员可以查看所有摄像头，如果deptDutyId为0则设为null以查询所有
            if (camera != null && camera.getDeptDutyId() != null && camera.getDeptDutyId() == 0) {
                camera.setDeptDutyId(null);
            }
        }

        PageHelper.startPage(pageNo, pageSize, true);
        List<Camera> list = cameraDao.selectCamera(camera);
        PageInfo<Camera> pageInfo = new PageInfo<Camera>(list);
        return ResponseResult.success(pageInfo);
    }

    @Override
    public ResponseResult selectCameraByKeyword(String keyword, int pageNo, int pageSize) {
        //如果keyword为空，默认检索全部摄像头
        if (pageNo < 1 || pageSize > 1000) {
            throw new AppException(AppExceptionCodeMsg.PAGE_NO_OR_SIZE_WRONG);
        }
        PageHelper.startPage(pageNo, pageSize, true);

        //下面的代码无法进行联表查询，查出工段、专业、值班室名称
        /*QueryWrapper<Camera> qw = new QueryWrapper<>();
        qw.like("cameraIndexCode", keyword).or().like("cameraName", keyword).orderByDesc("id");
        List<Camera> cameras = cameraDao.selectList(qw);*/

        List<Camera> cameras = cameraDao.selectCameraByKeyword(keyword);
        PageInfo<Camera> pageInfo = new PageInfo<Camera>(cameras);
        return ResponseResult.success(pageInfo);
    }

    @Override
    public ResponseResult deleteCamera(int id) {
        if(id > 0){
            Camera camera = cameraDao.selectById(id);
            if(camera != null){
                int rslt = cameraDao.deleteById(id);
                if(rslt > 0){
                    return ResponseResult.success("删除成功", null);
                } else {
                    throw new AppException(AppExceptionCodeMsg.DELETE_CAMERA_ERROR);
                }
            } else {
                throw new AppException(AppExceptionCodeMsg.ID_NOT_EXISTS);
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.ID_IS_NULL);
        }
    }

    @Override
    public ResponseResult selectCameras(Integer deptId, Integer worksectionId, Integer deptDutyId, Integer isEnabled, Integer isRecvEnabled, String keyword, int pageNo, int pageSize) {
        if (pageNo < 1 || pageSize > 1000) {
            throw new AppException(AppExceptionCodeMsg.PAGE_NO_OR_SIZE_WRONG);
        }

        // 获取当前用户角色和用户ID
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String userRole = (String) request.getAttribute("userRole");
        
        // 非管理员用户只能查看其所在值班室的摄像头
        if (!"管理员".equals(userRole)) {
            Integer userId = (Integer) request.getAttribute("userId");
            Dept userDept = deptDao.selectDutyRoomByid(userId);
            if (userDept == null) {
                // 如果用户没有关联值班室，返回空列表
                return ResponseResult.success(new PageInfo<>(new ArrayList<>()));
            }
            // 强制使用用户所在值班室ID
            deptDutyId = userDept.getId();
        } else {
            // 管理员如果传入deptDutyId为0，则设为null以查询所有
            if (deptDutyId != null && deptDutyId == 0) {
                deptDutyId = null;
            }
        }

        PageHelper.startPage(pageNo, pageSize, true);
        List<Camera> cameras = cameraDao.selectCameras(deptId, worksectionId, deptDutyId, isEnabled, isRecvEnabled, keyword);
        PageInfo<Camera> pageInfo = new PageInfo<Camera>(cameras);
        return ResponseResult.success(pageInfo);
    }

    @Override
    public ResponseResult updateCamera(Camera camera) {
        if (camera != null && camera.getId() != null && camera.getId() > 0) {
            Camera old = cameraDao.selectById(camera.getId());
            if (old != null) {
                //更新摄像头信息
                camera.setId(old.getId());
                if (!(cameraDao.updateById(camera) > 0)) {
                    throw new AppException(AppExceptionCodeMsg.UPDATE_CAMERA_ERROR);
                }
                //更新萤石云信息
                if (camera.getRealtimeHd() != null ||
                        camera.getRealtimeFast() != null ||
                        camera.getHistoryLocal() != null ||
                        camera.getHistoryCloud() != null) {
                    if (ezvizDao.findRecord(camera.getCameraIndexCode()) == null) {
                        if (!(ezvizDao.addRecord(camera) > 0)) {
                            throw new AppException(AppExceptionCodeMsg.ADD_EZVIZ_ERROR);
                        }
                    } else {
                        if (!(ezvizDao.updateRecord(camera) > 0)) {
                            throw new AppException(AppExceptionCodeMsg.UPDATE_EZVIZ_ERROR);
                        }
                    }
                }
                return ResponseResult.success("修改成功", null);
            } else {
                throw new AppException(AppExceptionCodeMsg.ID_NOT_EXISTS);
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.ID_IS_NULL);
        }



       /* ro.setData(null);
        if (camera.getCameraIndexCode() != null && !camera.getCameraIndexCode().equals("")) {
            Camera cam = cameraDao.selectCameraByIndexCode(camera.getCameraIndexCode());
            if (cam != null) {
                cameraDao.updateCamera(camera);
                //萤石云
                if (camera.getRealtimeHd() != null ||
                        camera.getRealtimeFast() != null ||
                        camera.getHistoryLocal() != null ||
                        camera.getHistoryCloud() != null) {
                    if (ezvizDao.findRecord(camera.getCameraIndexCode()) == null) {
                        ezvizDao.addRecord(camera);
                    } else {
                        ezvizDao.updateRecord(camera);
                    }
                }
                ro.setCode(0);
                ro.setMsg("修改成功");
            } else {
                ro.setCode(1);
                ro.setMsg("无此标识的摄像头");
            }
        } else {
            ro.setCode(2);
            ro.setMsg("错误，摄像头标识不能为空");
        }
        return ro;*/
    }

    @Override
    public ResponseResult getCameraCount() {
        // 获取当前用户角色和用户ID
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String userRole = (String) request.getAttribute("userRole");
        
        // 如果是管理员，返回所有摄像头数量
        if ("管理员".equals(userRole)) {
            return ResponseResult.success(cameraDao.getCameraCount());
        }
        
        // 非管理员，只返回关联值班室的摄像头数量
        Integer userId = (Integer) request.getAttribute("userId");
        Dept userDept = deptDao.selectDutyRoomByid(userId);
        if (userDept != null) {
            return ResponseResult.success(cameraDao.getCameraCountInDutyRoom(userDept.getId()));
        }
        
        // 如果用户没有关联值班室，返回0
        return ResponseResult.success(0);
    }

    @Override
    public ResponseResult getCameraSquare(String cameraIndexCode) {
        if (StringUtils.isNotBlank(cameraIndexCode)) {
            CameraSquare cs = cameraSquareDao.getCameraSquareByCameraIndexCode(cameraIndexCode);
            if (cs != null) {
                return ResponseResult.success(cs);
            } else {
//                throw new AppException(AppExceptionCodeMsg.ID_NOT_EXISTS);
                throw new AppException(50035, "此摄像头尚未配置九宫格设置");
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.PARAM_IS_NULL);
        }
    }

    @Override
    public ResponseResult updateCameraSquare(CameraSquare cameraSquare) {
        if (cameraSquare != null && StringUtils.isNotBlank(cameraSquare.getP5())) {
            if (cameraDao.selectCameraByIndexCode(cameraSquare.getP5()) != null
                    && cameraSquareDao.getCameraSquareByCameraIndexCode(cameraSquare.getP5()) != null) {
                if (cameraSquareDao.updateCameraSquare(cameraSquare) > 0) {
                    return ResponseResult.success("修改成功", null);
                } else {
                    throw new AppException(AppExceptionCodeMsg.UPDATE_CAMERA_SQUARE_ERROR);
                }
            } else {
                throw new AppException(AppExceptionCodeMsg.CENTRE_P5_NOT_EXIXTS);

            }
        } else {
            throw new AppException(AppExceptionCodeMsg.CENTRE_P5_IS_NULL);
        }
    }

    @Override
    public ResponseResult updateCameraSquareById(CameraSquare cameraSquare) {
        if(cameraSquare != null && cameraSquare.getId() != null && cameraSquare.getId() > 0){
            CameraSquare old = cameraSquareDao.selectById(cameraSquare.getId());
            if(old != null){
                cameraSquare.setId(old.getId());
                if(cameraSquareDao.updateById(cameraSquare) > 0){
                    return ResponseResult.success("修改成功", null);
                } else {
                    throw new AppException(AppExceptionCodeMsg.UPDATE_CAMERA_SQUARE_ERROR);
                }
            } else {
                throw new AppException(AppExceptionCodeMsg.ID_NOT_EXISTS);
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.ID_IS_NULL);
        }
    }

    @Override
    public ResponseResult addCameraSquare(CameraSquare cameraSquare) {
        if (cameraSquare != null && StringUtils.isNotBlank(cameraSquare.getP5())) {
            //查找Camera表中，有没此cameraIndexCode的摄像头
            if (cameraDao.selectCameraByIndexCode(cameraSquare.getP5()) == null) {
                throw new AppException(AppExceptionCodeMsg.CENTRE_P5_NOT_EXIXTS);
            } else {
                //如果在数据表中已经有该摄像头作为中心摄像头的九宫格，则修改记录
                if (cameraSquareDao.getCameraSquareByCameraIndexCode(cameraSquare.getP5()) != null) {
                    if (cameraSquareDao.updateCameraSquare(cameraSquare) > 0) {
                        return ResponseResult.success("添加成功", null);
                    } else {
                        throw new AppException(AppExceptionCodeMsg.UPDATE_CAMERA_SQUARE_ERROR);
                    }
                }
                //如果在数据表中没有该摄像头作为中心摄像头的九宫格，则新增记录
                else {
                    if (cameraSquareDao.insert(cameraSquare) > 0) {
                        return ResponseResult.success("添加成功", cameraSquare.getId());
                    } else {
                        throw new AppException(AppExceptionCodeMsg.ADD_CAMERA_SQUARE_ERROR);
                    }
                }
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.CENTRE_P5_IS_NULL);
        }
    }

    @Override
    public ResponseResult deleteCameraSquare(int id) {
        if (id > 0) {
            CameraSquare cameraSquare = cameraSquareDao.selectById(id);
            if (cameraSquare != null) {
                if (cameraSquareDao.deleteById(id) > 0) {
                    return ResponseResult.success("删除成功", null);
                } else {
                    throw new AppException(AppExceptionCodeMsg.DELETE_CAMERA_SQUARE_ERROR);
                }
            } else {
                throw new AppException(AppExceptionCodeMsg.ID_NOT_EXISTS);
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.ID_IS_NULL);
        }
    }

    @Override
    public ResponseResult getCameraSquareById(int id) {
        if(id > 0){
            CameraSquare cameraSquare = cameraSquareDao.selectById(id);
            if(cameraSquare != null){
                return ResponseResult.success(cameraSquare);
            } else {
                throw new AppException(AppExceptionCodeMsg.ID_NOT_EXISTS);
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.ID_IS_NULL);
        }
    }

    @Override
    public ResponseResult getCameraGroupById(int id) {
        if (id > 0) {
            CameraGroup cameraGroup = cameraGroupDao.selectById(id);
            if (cameraGroup != null) {
                if (cameraGroup.getCameras() != null && StringUtils.isNotBlank(cameraGroup.getCameras())) {
                    try {
                        List<Integer> ids = Arrays.stream(cameraGroup.getCameras().split(",")).map(s -> Integer.parseInt(s.trim())).collect(Collectors.toList());
                        List<Camera> cameras = new ArrayList<>();
                        if (ids != null && ids.size() > 0) {
                            for (Integer cid : ids) {
                                cameras.add(cameraDao.selectCameraByIdToSimpleMap(cid));
                            }
                        }
                        return ResponseResult.success(cameras);
                    } catch (Exception e) {
                        return ResponseResult.error(22200, "摄像头id集合格式错误");
                    }
                } else {
                    return ResponseResult.success(null);
                }
            } else {
                throw new AppException(AppExceptionCodeMsg.ID_NOT_EXISTS);
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.ID_IS_NULL);
        }
    }

    private void checkCameraIds(String idList){
        try {
            List<Integer> ids = Arrays.stream(idList.split(",")).map(s -> Integer.parseInt(s.trim())).collect(Collectors.toList());
            List<Camera> cameras = new ArrayList<>();
            if (ids != null && ids.size() > 0) {
                for (Integer cid : ids) {
                    cameras.add(cameraDao.selectCameraByIdToSimpleMap(cid));
                }
            }
        } catch (Exception e) {
            throw new AppException(22200, "摄像头id集合格式错误");
        }
    }

    @Override
    public ResponseResult addCameraGroup(CameraGroup cameraGroup) {
        if (cameraGroup != null && StringUtils.isNotBlank(cameraGroup.getGroupName())) {
            //摄像头组名称查重
            checkCameraGroupNameExist(cameraGroup.getGroupName());
            //摄像头id集合格式检查
            if(cameraGroup.getCameras() != null && StringUtils.isNotBlank(cameraGroup.getCameras())){
                checkCameraIds(cameraGroup.getCameras());
            }
            if (cameraGroupDao.insert(cameraGroup) > 0) {
                return ResponseResult.success("添加成功", cameraGroup.getId());
            } else {
                throw new AppException(AppExceptionCodeMsg.ADD_CAMERA_GROUP_ERROR);
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.NAME_IS_NULL);
        }
    }

    @Override
    public ResponseResult deleteCameraGroup(int id) {
        if(id > 0){
            CameraGroup cameraGroup = cameraGroupDao.selectById(id);
            if(cameraGroup != null){
                if(cameraGroupDao.deleteById(id) > 0){
                    return ResponseResult.success("删除成功", null);
                } else {
                    throw new AppException(AppExceptionCodeMsg.DELETE_CAMERA_GROUP_ERROR);
                }
            } else {
                throw new AppException(AppExceptionCodeMsg.ID_NOT_EXISTS);
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.ID_IS_NULL);
        }
    }

    /**
     * 摄像头组名称查重
     * @param name
     */
    private void checkCameraGroupNameExist(String name){
        QueryWrapper<CameraGroup> qw = new QueryWrapper<>();
        qw.eq("group_name", name);
        qw.select("id", "group_name");
        List<CameraGroup> cameraGroups = cameraGroupDao.selectList(qw);
        if(cameraGroups != null && cameraGroups.size() > 0){
            throw new AppException(AppExceptionCodeMsg.NAME_EXIST);
        }
    }

    @Override
    public ResponseResult updateCameraGroupById(CameraGroup cameraGroup) {
        if(cameraGroup != null && cameraGroup.getId() != null && cameraGroup.getId() > 0){
            CameraGroup old = cameraGroupDao.selectById(cameraGroup.getId());
            if(old != null){
                //名称查重
                if(!cameraGroup.getGroupName().equals(old.getGroupName())){
                    checkCameraGroupNameExist(cameraGroup.getGroupName());
                }
                //摄像头id集合格式检查
                if(cameraGroup.getCameras() != null && StringUtils.isNotBlank(cameraGroup.getCameras())){
                    checkCameraIds(cameraGroup.getCameras());
                }
                cameraGroup.setId(old.getId());
                if(cameraGroupDao.updateById(cameraGroup) > 0){
                    return ResponseResult.success("修改成功", null);
                } else {
                    throw new AppException(AppExceptionCodeMsg.UPDATE_CAMERA_GROUP_ERROR);
                }
            } else {
                throw new AppException(AppExceptionCodeMsg.ID_NOT_EXISTS);
            }
        } else {
            throw new AppException(AppExceptionCodeMsg.ID_IS_NULL);
        }
    }

    /**
     * 分页查询摄像头组集合
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public ResponseResult selectCameraGroups(String keyword, int pageNo, int pageSize) {
        if (pageNo < 1 || pageSize > 1000) {
            throw new AppException(AppExceptionCodeMsg.PAGE_NO_OR_SIZE_WRONG);
        }
        PageHelper.startPage(pageNo, pageSize, true);
        QueryWrapper<CameraGroup> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(keyword), "group_name", keyword);
        List<CameraGroup> groups = cameraGroupDao.selectList(queryWrapper);
        PageInfo<CameraGroup> pageInfo = new PageInfo<CameraGroup>(groups);
        return ResponseResult.success(pageInfo);
    }

    @Override
    public ResponseResult selectNotConfiguredCamera(int pageNo, int pageSize) {
        PageHelper.startPage(pageNo, pageSize, true);
        List<Camera> list = cameraDao.selectNotConfiguredCamera();
        PageInfo<Camera> pageInfo = new PageInfo<Camera>(list);
        return ResponseResult.success(pageInfo);
    }


}
